<template>
  <!-- 添加或修改客户信息管理对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="150px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="地区" prop="area">
                <el-select v-model="form.area" placeholder="请选择地区">
                  <el-option v-for="dict in dict.type.order_area" :key="dict.value" :label="dict.label"
                    :value="dict.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户编码" prop="code">
                <el-input v-model="form.code" placeholder="保存后自动生成" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入客户全称" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="打款税号" prop="taxNo">
                <el-input v-model="form.taxNo" placeholder="请输入打款税号" maxlength="18" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="地址" prop="addr">
                <el-input v-model="form.addr" placeholder="请输入地址" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系人" prop="linkMan">
                <el-input v-model="form.linkMan" placeholder="请输入客户名称" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="电话" prop="tel">
                <el-input v-model="form.tel" placeholder="请输入电话" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开户行" prop="bankName">
                <el-input v-model="form.bankName" placeholder="请输入开户行" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="银行账号" prop="bankNo">
                <el-input v-model="form.bankNo" placeholder="请输入银行账号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="营业执照" prop="file">
                <file-upload v-model="form.file" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    addAction,
    getById,
    updateAction,
    // treeselect
  } from '@/api/manage'
  import {
    treeselect
  } from '@/api/system/menu.js'

  export default {
    name: "GoodsCustomerForm",
    dicts: ['order_area'],
    components: {},
    data() {
      return {
        deptOptions: [],
        // 遮罩层
        loading: true,
        activeName: "first",
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          area: [{ required: true, message: "所属地区不能为空", trigger: "blur" }],
          name: [{ required: true,  message: "供应商名称不能为空", trigger: "blur" }],
        },
        url: {
          getById: '/goodsCustomer/goodsCustomer/',
          add: '/goodsCustomer/goodsCustomer/add',
          edit: '/goodsCustomer/goodsCustomer/edit',
        },
      };
    },
    created() {
      this.getTreeselect()
    },
    methods: {
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          simpleName: null,
          name: null,
          taxNo: null,
          addr: null,
          tel: null,
          bankName: null,
          bankNo: null,
          info: null,
          status: "0",
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          fazhanDate: null
        };
        this.resetForm("form");
      },
      selectDept(e) {
        let that = this;
        that.$set(that.form, "deptName", e.label);
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加客户信息管理";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids;
        getById(this.url.getById, id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改客户信息管理";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateAction(this.url.edit, this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.$emit('ok');
              });
            } else {
              addAction(this.url.add, this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.$emit('ok');
              });
            }
          }
        });
      },






    }
  };
</script>
